package cn.cdu.medical.controller;

import cn.cdu.basics.baseVo.Result;
import cn.cdu.basics.utils.ResultUtil;
import cn.cdu.medical.entity.MedicalRecordRevision;
import cn.cdu.medical.service.MedicalRecordRevisionService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Tag(name = "电子病历修改记录接口")
@RequestMapping("/zwz/medical-record-revisions")
@CrossOrigin
public class MedicalRecordRevisionController {

    @Autowired
    private MedicalRecordRevisionService revisionService;

    @PostMapping
    public Result<MedicalRecordRevision> saveRevision(@RequestBody MedicalRecordRevision revision) {
        boolean success = revisionService.saveRevision(revision);
        if (success) {
            return new ResultUtil<MedicalRecordRevision>().setData(revision);
        }
        return new ResultUtil<MedicalRecordRevision>().setErrorMsg("保存修订记录失败");
    }

    @GetMapping("/{recordId}")
    public Result<List<MedicalRecordRevision>> getRevisionHistory(@PathVariable String recordId) {
        List<MedicalRecordRevision> revisions = revisionService.getRevisionHistory(recordId);
        return new ResultUtil<List<MedicalRecordRevision>>().setData(revisions);
    }
} 